/**
 * Created by Administrator on 2017-07-25.
 */
'use strict'
import Vue from 'vue'
var modelDataExploreTemplete = require('html!./model_use_data_explore.html');
require('./model.less');
module.exports = {
  template: modelDataExploreTemplete,
  data:function(){
    return{
      modelId:'',
      modelName:'',
      modelDesc:'',
      modelFieldData:[],
      userId:localStorage.getItem('userId'),
      oldTableName:""
    }
  },
  created:function(){
    this.modelId = this.$route.query.modelId;
    this.modelName = this.$route.query.modelName;
    this.modelDesc = this.$route.query.modelDesc;
    this.initDataList();
  },
  beforeMount:function(){

  },
  updated:function(){
    //this.initCommonModel();
  },
  methods:{
    initDataList:function(){
      var me = this;
      this.$http.get('/eyeModelController/getUploadDataListByUseModel.do?modelId='+me.modelId)
        .then(function(res){
          if(res.data.status === 'OK'){
            this.modelFieldData = res.data.result.list;
          }else{
            layer.msg("没有相关数据");
          }
        }.bind(this));
    },
    submitPre:function () {
      var me = this;

      me.$router.push({ path: '/product/dataType', query: {oldModelId:me.modelId, modelId: me.modelId+"",modelName:me.modelName,modelDesc:me.modelDesc }});
    },
    submit:function () {
      var me = this;
      var layLoad = layer.load(2, {shade: 0.1, area: ['32px', '64px']})
      $.ajax({
        url: Vue.prototype.$http.defaults.baseURL + '/algorithmController/doInputSetTSDataByUseModel.do',
        method: 'post',
        data: {
          'modelId': me.modelId
        },
        dataType: 'json',
        success: function (res) {
          layer.close(layLoad);

          console.log(res);
          if (res.code == '000000') {
            localStorage.setItem('modelId', me.modelId);
            me.oldTableName=res.result;
            localStorage.setItem('oldTableName', me.oldTableName);
            // alert(me.oldTableName);
            me.getDataList()//执行算法
          } else {
            layer.msg(res.message);
          }
        },
        error: function (error) {
          console.error(error, 'error')
        }
      })
      // me.$router.push({ path: '/product/inputSet', query: { modelId: me.modelId+"" }});
    },
    /**
     * 执行算法
     */
    getDataList:function () {
      var me = this;
      me.layLoad = layer.load(2, {shade: 0.1, area: ['32px', '64px']});
      this.$http.get(Vue.prototype.$http.defaults.baseURL +'/eyeShowResultController/getDataList.do?modelId='+me.modelId+'&tableName='+me.oldTableName).then(function(res) {
        //获取变量列表
        if(res.data.status === 'OK') {
          console.log("执行中");
          localStorage.setItem('isFromTrail',false);
          me.$router.push({path:'/product/export-result',query: { type: "edit",modelId:me.modelId,modelDesc:me.modelDesc,modelName:me.modelName }});
        }
      });
    },

  }
}
